
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the Hospital table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Hospital_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@LocalId nvarchar (20)  = null ,

	@Title nvarchar (50)  = null ,

	@Alias nvarchar (50)  = null ,

	@Introduction ntext   = null ,

	@Thumbnail varchar (200)  = null ,

	@ClinicTime nvarchar (500)  = null ,

	@Contact nvarchar (500)  = null ,

	@CreatedDate datetime   = null ,

	@UpdatedDate datetime   = null ,

	@CreatedUser varchar (50)  = null ,

	@UpdatedUser varchar (50)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [LocalId]
	, [Title]
	, [Alias]
	, [Introduction]
	, [Thumbnail]
	, [ClinicTime]
	, [Contact]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
    FROM
	[dbo].[Hospital]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([LocalId] = @LocalId OR @LocalId IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([Alias] = @Alias OR @Alias IS NULL)
	AND ([Thumbnail] = @Thumbnail OR @Thumbnail IS NULL)
	AND ([ClinicTime] = @ClinicTime OR @ClinicTime IS NULL)
	AND ([Contact] = @Contact OR @Contact IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([UpdatedDate] = @UpdatedDate OR @UpdatedDate IS NULL)
	AND ([CreatedUser] = @CreatedUser OR @CreatedUser IS NULL)
	AND ([UpdatedUser] = @UpdatedUser OR @UpdatedUser IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [LocalId]
	, [Title]
	, [Alias]
	, [Introduction]
	, [Thumbnail]
	, [ClinicTime]
	, [Contact]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
    FROM
	[dbo].[Hospital]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([LocalId] = @LocalId AND @LocalId is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([Alias] = @Alias AND @Alias is not null)
	OR ([Thumbnail] = @Thumbnail AND @Thumbnail is not null)
	OR ([ClinicTime] = @ClinicTime AND @ClinicTime is not null)
	OR ([Contact] = @Contact AND @Contact is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([UpdatedDate] = @UpdatedDate AND @UpdatedDate is not null)
	OR ([CreatedUser] = @CreatedUser AND @CreatedUser is not null)
	OR ([UpdatedUser] = @UpdatedUser AND @UpdatedUser is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
